package org.example.trainTicketSystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.trainTicketSystem.entity.SaleRecord;
import org.example.trainTicketSystem.mapper.SaleRecordMapper;
import org.example.trainTicketSystem.service.SaleRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SaleRecordServiceImpl extends ServiceImpl<SaleRecordMapper, SaleRecord> implements SaleRecordService {

    @Autowired
    private final SaleRecordMapper saleRecordMapper;

    public SaleRecordServiceImpl(SaleRecordMapper saleRecordMapper) {
        this.saleRecordMapper = saleRecordMapper;
    }

    @Override
    public Page<SaleRecord> getSaleRecordsByUserId(int userId, int page, int size) {
        Page<SaleRecord> saleRecordPage=new Page<>(page, size);
        QueryWrapper<SaleRecord> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return saleRecordMapper.selectPage(saleRecordPage,queryWrapper);
    }
}
